package cn.lili.common.properties;

import lombok.Data;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 环境
 *
 * @author moxingjian
 * @version 1.0
 * @date 2023-10-20 17:54
 * <p>
 * 版本更新：
 * 更新版本号    更新人      更新时间      更新内容
 */
@Data
@Component
public class ProfileProperties implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    /**
     * 是否为生产环境
     *
     * @return true：生产环境
     */
    public static boolean isProd() {
        return "prod".equals(ProfileProperties.getActiveProfile());
    }

    public static String getActiveProfile() {
        return applicationContext.getEnvironment().getActiveProfiles()[0];
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (ProfileProperties.applicationContext == null) {
            ProfileProperties.applicationContext = applicationContext;
        }
    }
}
